<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		
		<div class="test"></div>
		<p class="test1"></p>
		<h1 class="test test1"></h1>
		
		<script>
			/*var clsName = document.getElementsByClassName('test');
			console.log(clsName);*/
			
			
			function getClassName(clsName) {
				var allElement = document.body.getElementsByTagName('*');
				//console.log(allElement);
				var arr = [];
				for(var i = 0; i < allElement.length; i++) {
					if(allElement[i].getAttribute('class')) {
						//console.log(allElement[i].getAttribute('class').split(' '));
						/*if(allElement[i].getAttribute('class').split(' ').indexOf('test') != -1) {
							arr.push(allElement[i]);
						}*/
						var clsArr = allElement[i].getAttribute('class').split(' ');
						for(var o = 0; o < clsArr.length; o++) {
							if(clsArr[o] == clsName) {
								arr.push(allElement[i]);
								continue;
							}
						}
					}
					
				}
				return arr;
			}
			
			var cln = getClassName('test');
			console.log(cln);
			
			
			/*var arr2 = ['test', 'test2', 'test3'];
			console.log(arr2.indexOf('test1'));*/
		</script>
	</body>
</html>
